package com.nuc.bigdata.orm.entity;

import com.nuc.bigdata.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.Date;

/**
 * DynamicInsert；DynamicUpdate这两个注解的作用就是：当数据库表中某个字段设置为NOT NULL DEFAULT 'AAA'
 * 的时候，后端插入数据库没有给这个字段赋值，即字段为NULL，构造insert语句时能够动态的去掉为NULL的字段，从而绕过NOT NULL
 * 取到默认值
 * @author JackLuo
 * @date 2019/10/22
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "user")
@DynamicInsert
@DynamicUpdate
public class User extends BaseEntity implements Serializable {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private Long id;

    @NotEmpty(message = "用户Id不为空")
    private String userId;

    @Length(max = 10)
    private String loginName;

    @Length(max = 50)
    private String email;

    @Length(max = 11)
    private String phoneNumber;

    @NotEmpty(message = "密码不能为空")
    @Length(max = 30,min = 6)
    private String password;

    private Long role;

    private Long sex;

    @Length(max = 200)
    private String headPicture;

    @Length(max = 200)
    private String tag;

    private Date birthday;

    @Length(max = 200)
    private String location;
}
